/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ages.graphics

import com.sun.opengl.util.texture.TextureData
import com.sun.opengl.util.texture.TextureIO
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
import javax.media.opengl.GL

class SpriteBuffer(filename:String,rows:Int,cols:Int,hue:Float) {

  var displayLists:Array[Array[Int]] =_

  def this(filename:String,rows:Int,cols:Int) = this(filename,rows,cols,1)
  
  val tl = new TextureLoader();
  def getRows = rows
  def getCols = cols

//  val bufferedImage = ImageIO.read(getClass().getResource(filename))
//  println(getClass().getResource(filename))
//  val texData = new TextureData(bufferedImage.getType(), BufferedImage.TYPE_INT_ARGB, true, bufferedImage);
//  val spriteSheet = tl.load(texData);
  val spriteSheet = tl.oldLoad(filename)
  private val dimX = spriteSheet.getWidth;
  private val dimY = spriteSheet.getHeight;
  private val memory = spriteSheet.getEstimatedMemorySize();
  private val frameX = spriteSheet.getWidth/cols.toDouble;
  private val frameY = spriteSheet.getHeight/rows.toDouble;
  private val dimension = frameX/dimX

  def dimRatio = dimension
  def frameHeight = frameX
  def frameWidth = frameY

  def drawWithoutDisplaylist(gl:GL,row:Int, col:Int)
  {
//    spriteSheet.bind();
          gl.glDisable(GL.GL_LIGHTING)
    val dm = new SpriteBufferManager(gl)
    dm.drawQuad(this, row, col, frameX.toInt);
  }

//        val dimension = dimension/2;
//        val dm = DisplaylistManager.getInstance();
//        val frames = dm.getSpriteList(this);


}
